<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>
<!--
<link type="text/css" href="<?php echo base_url(); ?>ajaxupload/ajaxfileupload.css" rel="stylesheet" /> 
<script src="<?php echo base_url(); ?>ajaxupload/jquery.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>ajaxupload/ajaxfileupload.js" type="text/javascript"></script>
-->

<script>
//SCRIPT INI HARUS DIATAS, TIDAK BOLEH DIBAWAH
$("#r_name").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_nik_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_id").val(data.DetailEmp.HR_ID);
                $("#r_nama").val(data.DetailEmp.NAME);
                $("#r_mgrid").val(data.DetailEmp.MANAGER_ID);
				$("#r_mgr").val(data.DetailEmp.MANAGER);
				$("#r_dept").val(data.DetailEmp.ORG);
				$("#r_job").val(data.DetailEmp.JOB_POSITION);														
			}
			
		});
});

$("#pRmCategory").change(function()
			{
			    var typId=$('#pRmTypeId').val();
				var vid=$(this).val();
                var pecahan=vid.split('~');
                var nilai1=pecahan[0];
                var nilai2=pecahan[1];
				var id=vid;
				var dataString = {typid:typId,id:nilai1};
	
				$.ajax({
					type: "POST",
					url:"<?php echo site_url('search_global/globals_floor_detail'); ?>",
                    dataType: 'json',
					data: dataString,
                    success: function(data)
            			{
            				$("#pRmFloor").val(data.DetailFloor.MST_FLOOR_DESC);														
            			}
				});

			});   
</script>
<script>
	$(function() {     //HARUS TERLETAK PALING ATAS DIANTARA LAINNYA
		$("input[id^='datepicker']").datetimepicker({
			scrollInput: false,
			yearOffset:0,
			lang:'en',
			timepicker:false,
			datepicker:true,
			format:'d/m/Y',
			formatDate:'d/m/Y',
			/*minDate:'-1970/01/01',
			onGenerate:function( ct ){
				$(this).find('.xdsoft_date.xdsoft_weekend')
					.addClass('xdsoft_disabled');
			}*/
		});
	});
</script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#pRmType').select2({
            placeholder: "",
            allowClear: true
        });
    });
</script>

<script>
$(document).ready(function()
	{
		$("#pRmTypeId").change(function()
			{
				var vid=$(this).val();
                var pecahan=vid.split('-');
                var nilai1=pecahan[0];
                var nilai2=pecahan[1];
				var id=vid;
				var dataString = 'id='+ nilai1;
	
				$.ajax({
					type: "POST",
					url:"<?php echo site_url('search_global/getCategoryFromType'); ?>",
					data: dataString,
					cache: false,
					success: function(html)
						{
							$("#pRmCategory").html(html);
						}
				});

			});
	});
</script>

<script>
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        });
    }
    function editSrnKrjRmSave() {
        var vid=$('#pRmTypeId').val();
            var pecahan=vid.split('-');
            var nilai1=pecahan[0];
            var nilai2=pecahan[1];
        var cid=$('#pRmCategory').val();
            var pecahanC=cid.split('~');
            var nilaiC1=pecahanC[0];
            var nilaiC2=pecahanC[1];    
        var desc=$('#pRmDesc').val();
            var nilai3=desc.trim();
            
        $.post("<?= site_url() ?>search_global/edit_reqSave", {
            pRmID    		    : $('#pCtrlID').val(),
            pCType              : $('#pCType').val(),
            
            pRmType    			: nilai2,
            pRmCategory         : nilaiC2,
            pRmDesc    			: nilai3,
            //pChek    			: $('#pChek').val(),
            pRmSerial    		: $('#pRmSerial').val(),
            pAtasanNik    		: $('#r_mgrid').val(),
            pRmFloor    		: $('#pRmFloor').val(),
            //pRmSuite   		: $('#pRmSuite').val(),
            pRmDate1   		    : $('#datepicker1').val(),
            pRmDate2    		: $('#datepicker2').val(),
            pNikFor    			: $('#r_id').val()
        },
        function(data) {
            window.location = '<?php echo base_url(); ?>search_global/search_global';
        }
        );
    }
</script>

<?php 
	foreach($getDetail as $a){
		$aRmID   		= $a['RM_ID'];
		$aRmDate  		= $a['RM_DATE'];
		$aRmDelivery    = $a['RM_DELIVERY'];
		$aRmTurn        = $a['RM_RETURN'];
		$aRmType 		= $a['RM_TYPE'];
		$aRmTypeId 		= $a['MST_TYPE_ID'];
		$aRmCategory 	= $a['RM_CATEGORY'];
		$aRmVendor		= $a['RM_VENDOR'];
		
		$aRmAppAtasan	= $a['RM_ATASAN_APP'];
		$aRmAppGa   	= $a['RM_GA_APP'];
		$aRmFloor 		= $a['RM_FLOOR'];
		$aRmDesc	    = $a['RM_DESCRIPTION'];
		$aRmSerial		= $a['RM_SERIAL'];
		$aRmSuite		= $a['RM_SUITE'];
		$aRmSHour		= $a['RM_SHOUR'];
		$aRmSMinute		= $a['RM_SMINUTE'];
		$aRmEHour		= $a['RM_EHOUR'];
		$aRmEMinute		= $a['RM_EMINUTE'];
		$aRmUntukNik	= $a['RM_UNTUK_NIK'];
		$aRmAtasanId	= $a['RM_ATASAN_ID'];
        $aAtasanName 	= $a['ATASANNAME'];
    	$cName			= $a['NIKNAME'];
    	$cJob			= $a['NIKJOBPOSITION'];
    	$cOrg			= $a['NIKORG'];
 	}
    /*
	if(empty($org)){
		   $org = dbora_getorg("$nik");
	}*/
?>

<div id="top" >
<form id="formarea" role="form" method="post" action="" class="form-horizontal"  enctype="multipart/form-data"> 
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pCtrlID" name="pCtrlID" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" name="pCType"/>
<!--<div class="container">-->
	<div class="col-md-offset-0">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Request By (*Tidak Pengaruh saat Update)</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-3">Nama</label>
							<div class="col-md-7">
                            <input type="text"  id="r_nama" class="select2 form-control input-sm" value="<?php echo $cName;?>" readonly=""/>
                            <input type="text"  id="r_name" class="select2 form-control input-sm" value="<?php echo $cName;?>"/></div>
						</div>					
						<div class="form-group">
							<label class="control-label col-md-3">Nik</label>
							<div class="col-md-3">
                            <input type="text"  id="r_id" class="form-control input-sm" readonly="" value="<?php echo $aRmUntukNik;?>"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">Nama Atasan</label>
							<div class="col-md-7">
                                <input type="hidden" id="r_mgrid" class="form-control input-sm" readonly="" value="<?php echo $aRmAtasanId;?>"/>
                                <input type="text" id="r_mgr" class="form-control input-sm" readonly="" value="<?php echo $aAtasanName;?>"/>
                            </div>
						</div>
					</div>
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7">
                            <input type="text" id="r_dept" class="form-control input-sm" readonly="" value="<?php echo $cOrg;?>"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8">
                            <input type="text" id="r_job" class="form-control input-sm" readonly="" value="<?php echo $cJob;?>"/></div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Form</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-2">Type</label>
							<div class="col-md-4">
                            <!--
                            <input type="hidden" id="pRmTypeId" value="<?php echo $aRmTypeId;?>"/>
                            <input type="text" value="<?php echo $aRmType;?>" id="pRmType" class="form-control input-sm" readonly="" />
                            -->
                            <select id="pRmTypeId" class="form-control select2"  style="width:230px;">
                                        <option value="">-- select --</option>
                                        <?php
                                        foreach($getType as $typ){
                                        ?>
                                        <option value="<?php echo $typ['KEY']."-".$typ['VALUE'];?>" <?php if($aRmTypeId==$typ['KEY']){?> selected="" <?php } ?> >
                                            <?php echo $typ['VALUE'];?>
                                        </option>
                                        <?php
                                        }
                                        ?>
                            </select>
                            </div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Category</label>
							<div class="col-md-7">
                            <select id="pRmCategory" class="form-control select2"  style="width:230px;">
                                <?php
                                foreach($getCategory as $cat){
                                    ?>
                                    <option value="<?php echo $cat['KEY']."~".$cat['VALUE'];?>" <?php if($aRmCategory==$cat['VALUE']){?>selected=""<?php } ?>>
                                        <?php echo $cat['VALUE'];?>
                                    </option>
                                    <?php
                                }
                                ?>            
                            </select>
                            <!--<input type="text" value="<?php echo $aRmCategory;?>" name="pRmCategory" class="form-control input-sm" readonly="" />-->
                            </div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Lantai</label>
							<div class="col-md-2">
                            <input type="text" value="<?php echo $aRmFloor;?>" id="pRmFloor" class="form-control input-sm" readonly="" /></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Serial#</label>
							<div class="col-md-7"><input type="text" value="<?php echo $aRmSerial;?>" id="pRmSerial" class="form-control input-sm" /></div>
						</div>
					</div>
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Request Date</label>
							<div class="col-md-4">
								<div class="input-group">
                                    <input type="text" class="form-control text-center input-sm" name="pRmDate1" id="datepicker1" value="<?php echo $aRmDelivery; ?>"/>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Promise Date</label>
							<div class="col-md-4">
								<div class="input-group">
									<input type="text" class="form-control text-center input-sm" name="pRmDate2" id="datepicker2" value="<?php echo $aRmTurn; ?>"/>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Description</label>
							<div class="col-md-7">
								<textarea id="pRmDesc" class="form-control input-sm" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;">
                                <?php echo $aRmDesc;?>
                                </textarea>
							</div>
						</div>
					</div>
					
                    <div class="row"> 
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="control-label col-md-3"></label>
        						<div class="col-sm-2">
                                    <button type="button" class="btn btn-primary btn-block" onclick="editSrnKrjRmSave();">Submit</button>
                                </div>
                                <div class="col-sm-2">
                                    <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                                </div>
    				        </div>
                        </div>                   
                    </div>
				</div>
			</div>
		</div>
	</div>
<!--</div>-->
</form>
</div>